home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWMemory / Include / FWMemMgr.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  4.1 KB  |  149 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMemMgr.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMEMMGR_H
  11. #define FWMEMMGR_H
  12.  
  13. #include <stddef.h>
  14.  
  15. #ifndef FWSTDDEF_H
  16. #include "FWStdDef.h"
  17. #endif
  18.  
  19. #ifndef FWPRIEXC_H
  20. #include "FWPriExc.h"
  21. #endif
  22.  
  23. #ifndef FWEXCDEF_H
  24. #include "FWExcDef.h"
  25. #endif
  26.  
  27. #ifndef FWNEW_H
  28. #include "FWNew.h"
  29. #endif
  30.  
  31. #if defined(FW_BUILD_MAC) && !defined(__MEMORY__)
  32. #include <Memory.h>
  33. #endif
  34.  
  35. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  36. #include <Errors.h>
  37. #endif
  38.  
  39. #ifdef FW_BUILD_WIN32
  40.  
  41. #include <Windows.h>
  42.  
  43. // Windows 32 API macro that conflicts with a method in FW_CMemoryManager
  44. #ifdef CopyMemory
  45. #undef CopyMemory
  46. #endif
  47.  
  48. #endif
  49.  
  50. #if FW_LIB_EXPORT_PRAGMAS
  51. #pragma lib_export on
  52. #endif
  53.  
  54. #if defined(FW_BUILD_MAC)
  55. const FW_PlatformError FW_xMemoryExhausted = memFullErr;
  56. #elif defined(FW_BUILD_WIN)
  57. const FW_PlatformError FW_xMemoryExhausted = -30999; //!!!JEL: Need correct value!!!
  58. #endif
  59.  
  60.  
  61. //========================================================================================
  62. // Forward class declarations
  63. //========================================================================================
  64.  
  65. struct MemHeap;
  66.  
  67. //========================================================================================
  68. // Type definitions
  69. //========================================================================================
  70.  
  71. typedef void (*FW_PFVV)();    
  72.     // Pointer to function returning void.
  73.     // Used with set_new_handler.  See ARM, pp 280-81.
  74.  
  75. //========================================================================================
  76. // Global procedure definitions
  77. //========================================================================================
  78.  
  79. void*         operator new(size_t size);
  80. void          operator delete(void* block);
  81.  
  82. #ifdef FW_SET_NEW_HANDLER
  83. FW_PFVV set_new_handler(FW_PFVV handler);
  84.     // See ARM, pp 280-81.
  85. #endif
  86.  
  87. #ifdef FW_BUILD_MAC
  88. void SetStackSpace(long numBytes);
  89.  
  90. // MetroWerks won't compile this, don't know if we use it? [AMB]
  91. //pascal Ptr GetCurrentStackBase() = {    /*  kMoveLAbsolute                */    0x2eb8,            
  92. //                                         /*  CurStackBase                */     0x0908 };
  93. //                                        /*  MOVE.L CurStackBase,(SP)    */
  94. #endif
  95.  
  96. //========================================================================================
  97. // CLASS FW_CMemoryManager
  98. //========================================================================================
  99.  
  100. class FW_CLASS_ATTR FW_CMemoryManager
  101. {
  102. public:
  103.  
  104.     // Utility routines for manipulating blocks of memory
  105.     static void CopyMemory(const void* const source,
  106.                            void* const destination,
  107.                            unsigned long bytesToMove);
  108.     static void SetMemory(void* aBlock,
  109.                           unsigned long bytesToSet,
  110.                           unsigned char byteValue);
  111.     static void* AddOffsetToPointer(void* pointer,
  112.                                     unsigned long Offset);
  113.  
  114.     // when resizable, pointer-based blocks are needed:
  115.     static void* AllocateBlock(unsigned long bytesRequested);
  116.     static void* ResizeBlock(void* aBlock,
  117.                              unsigned long bytesRequested);
  118.     static void FreeBlock(void* aBlock);
  119.  
  120.     // when platform specific handles are needed:
  121.     static FW_PlatformHandle AllocateSystemHandle(unsigned long bytesRequested);
  122.     static FW_PlatformHandle ResizeSystemHandle(FW_PlatformHandle aHandle,
  123.                                                 unsigned long bytesRequested);
  124.     static void FreeSystemHandle(FW_PlatformHandle aHandle);
  125.     static void* LockSystemHandle(FW_PlatformHandle aHandle);
  126.     static void UnlockSystemHandle(FW_PlatformHandle aHandle);
  127.     static unsigned long GetSystemHandleSize(FW_PlatformHandle aHandle);
  128.     static FW_PlatformHandle CopySystemHandle(FW_PlatformHandle aHandle);
  129.  
  130.     //internal methods
  131.     // when resizable, pointer-based blocks are needed, no debug checking:
  132.     static void InitializeRawBlock(void* aBlock,
  133.                                    unsigned long sizeBlock);
  134.  
  135.     static void DefaultNewHandler();
  136.  
  137. private:
  138.     static MemHeap* GetMemoryHeap();
  139.  
  140.     FW_CMemoryManager() {};
  141.         // abstract class.  Note that all methods are statics.
  142. };
  143.  
  144. #if FW_LIB_EXPORT_PRAGMAS
  145. #pragma lib_export off
  146. #endif
  147.  
  148. #endif
  149.